From 031e1c799f5930e2e27278a629ef2e61de91679f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Wed, 24 Sep 2025 15:44:13 +0200 Subject: [PATCH] dhcpv4: dhcpv4_fr_rand_delay() fixups MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Move constants to dhcpv4.h, and make their names more descriptive. Also, use abs() instead of labs(), since "msecs" is an int. Signed-off-by: David Härdeman Link: https://github.com/openwrt/odhcpd/pull/266 Signed-off-by: Álvaro Fernández Rojas --- src/dhcpv4.c | 4 +--- src/dhcpv4.h | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 15425a5..25fcdb6 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -280,13 +280,11 @@ static void dhcpv4_fr_delay_timer(struct uloop_timeout *event) static void dhcpv4_fr_rand_delay(struct dhcp_assignment *a) { -#define MIN_DELAY 500 -#define MAX_FUZZ 500 int msecs; odhcpd_urandom(&msecs, sizeof(msecs)); - msecs = labs(msecs)%MAX_FUZZ + MIN_DELAY; + msecs = abs(msecs) % DHCPV4_FR_MAX_FUZZ + DHCPV4_FR_MIN_DELAY; uloop_timeout_set(&a->fr_timer, msecs); a->fr_timer.cb = dhcpv4_fr_delay_timer; diff --git a/src/dhcpv4.h b/src/dhcpv4.h index 7db5c52..d54aedb 100644 --- a/src/dhcpv4.h +++ b/src/dhcpv4.h @@ -21,6 +21,9 @@ #define DHCPV4_MIN_PACKET_SIZE 300 +#define DHCPV4_FR_MIN_DELAY 500 +#define DHCPV4_FR_MAX_FUZZ 500 + enum dhcpv4_op { DHCPV4_BOOTREQUEST = 1, DHCPV4_BOOTREPLY = 2 -- 2.30.2